package com.qfedu.biz.impl;

import com.qfedu.biz.OrderDetatilBiz;
import com.qfedu.entity.GoodsEntity;
import com.qfedu.entity.OrderDetailEntity;
import com.qfedu.mapper.OrderDetailPojoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class OrderDetailBizimpl implements OrderDetatilBiz {
@Autowired
private OrderDetailPojoMapper orderDetailPojoMapper;
    @Override
    public Boolean insertOrderDetail(List<GoodsEntity> goodslist,String oid) {
        int allcount=0;
        float allprice=0;
        String gid=null;
        for (GoodsEntity goodsEntity:goodslist){
          allcount=goodsEntity.getGoodscount();
          allprice= goodsEntity.getGoodscount() * goodsEntity.getGprice() * goodsEntity.getGdiscount();
             gid = goodsEntity.getGid();
            Boolean aBoolean = orderDetailPojoMapper.insertOrderDetail(oid, gid, allcount, allprice);
            if (!aBoolean){
                return false;
            }
        }
        return true;
    }

    //根据定单查询订单详情
    public List<OrderDetailEntity> queryOrderDetail(String oid){
        List<OrderDetailEntity> orderDetailEntities = orderDetailPojoMapper.queryOrderDetail(oid);
        return orderDetailEntities;
    }
}
